package com.spsoft.security.config;

import com.spsoft.core.config.VmsProperties;
import com.spsoft.security.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.stream.Collectors;

@Configuration
//定制SpringMVC的一些功能都使用WebMvcConfigurer
public class SecurityWebConfig implements WebMvcConfigurer {


    @Autowired
    private VmsProperties vmsProperties;
    /**
     * 配置拦截器
     * @param registry 相当于拦截器的注册中心
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns( vmsProperties.getIgnoreUrls().stream().collect(Collectors.toList()));
    }
}
